@extends('layouts.admin')
@section('style')
@endsection
@section('content')
    <div class="layui-container openframe">
        <form method="post" action="{{ url('user/role/'.$vo->id) }}" id="UserForm" class="layui-form" novalidate="1">
            {{ csrf_field() }}
            <div class="layui-form-item">
                <label class="layui-form-label"><span>*</span>登录手机号</label>
                <div class="layui-input-block">
                    <input type="text" readonly data-title="登录手机号" value="{{ $vo->mobile }}" id="mobile"
                           class="layui-input layui-disabled">
                </div>
            </div>
            <div class="layui-form-item">
                 <label class="layui-form-label">角色列表</label>
                 <div class="layui-input-inline">
                     @foreach($roles as $role)
                         <input type="checkbox" name="role_ids[]" value="{{ $role->id }}"
                                lay-skin="primary" title="{{ $role->display_name }}"
                                @if($role->authorizedByAdmin($id)) checked @endif
                         />
                     @endforeach
                 </div>
            </div>
        </form>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        var doSubmit = null;
        layui.use(['form', 'element', 'layer', 'utils', 'formField'], function () {
            var form = layui.form;
            var element = layui.element;
            var URL = layui.utils.URL;
            var $ = layui.$;
            doSubmit = function(callback){
                var url = $("#UserForm").prop('action');
                var data = $("#UserForm").serialize();
                URL.post(url, data, {
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 1) {
                            layer.msg(res.message, {icon: 6, times: 2000}, function () {
                                callback();
                            })
                        } else {
                            layer.msg(res.message, {icon: 5, times: 2000});
                        }
                    }
                })
                return false;
            }
        });

    </script>
@endsection